package com.example.shop_2305.adapter

import android.graphics.Color
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.lib_base.entity.ExplosiveMoney
import com.example.shop_2305.R

class TypeAdapter:BaseQuickAdapter<ExplosiveMoney,BaseViewHolder>(R.layout.item_type) {
    //默认选中的
    var selectType = 4
    override fun convert(holder: BaseViewHolder, item: ExplosiveMoney) {
        holder.setText(R.id.type_info,item.info)
        holder.setText(R.id.type_name,item.name)
        if(selectType==item.type.toInt()){
            holder.getView<TextView>(R.id.type_info).setTextColor(Color.RED)
            holder.getView<TextView>(R.id.type_name).setTextColor(Color.RED)
            holder.getView<LinearLayout>(R.id.ll_type).setBackgroundResource(R.drawable.bg_type)
        }else{
            holder.getView<TextView>(R.id.type_info).setTextColor(Color.BLACK)
            holder.getView<TextView>(R.id.type_name).setTextColor(Color.BLACK)
            holder.getView<LinearLayout>(R.id.ll_type).background = null
        }
    }
    //点击发生变化
    fun setType(type:Int){
        selectType = type
        notifyDataSetChanged()//刷新适配器，数据发生变化
    }
}